﻿package com.saint.utils{
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	import flash.geom.Matrix;
	
	public class BitmapUtils{
		
		public function BitmapUtils():void{
		}
		
		public static function snapClip(clip:DisplayObject, area:Sprite):BitmapData{
			/* pass in a display oject and get back bitmap data. happy days */
			var bounds:Rectangle = area.getBounds(area);
			var bitmap:BitmapData = new BitmapData( int( bounds.width + 0.5 ), int( bounds.height + 0.5 ), true, 0 );
			bitmap.draw(clip, new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y));
			return bitmap;
		}
		
		public static function snapClipRect((lip:DisplayObject, bounds:Rectangle ):BitmapData {
			/* pass in a display oject and get back bitmap data. happy days */
			var bitmap:BitmapData = new BitmapData( int( bounds.width + 0.5 ), int( bounds.height + 0.5 ), true, 0 );
			bitmap.draw(clip, new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y));
			return bitmap;
		}
	}
	
	
}